package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.ClientPlan;
import com.olddriver.crm.domain.Employee;
import com.olddriver.crm.mapper.ClientPlanMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.ClientPlanQueryObject;
import com.olddriver.crm.service.IClientPlanService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ClientPlanServiceImpl implements IClientPlanService {

    @Autowired
    private ClientPlanMapper clientPlanMapper;

    public int save(ClientPlan clientPlan){
        //设置录入人
        Employee inputUser = (Employee) SecurityUtils.getSubject().getPrincipal();
        clientPlan.setInputUser(inputUser);
        return clientPlanMapper.save(clientPlan);
    }

    public void update(ClientPlan clientPlan) {
        clientPlanMapper.update(clientPlan);
    }

    public void delete(Long id) {
        clientPlanMapper.delete(id);
    }

    public ClientPlan get(Long id) {
        return clientPlanMapper.get(id);
    }

    public List<ClientPlan> list() {
        return clientPlanMapper.list();
    }

    public PageResult query(ClientPlanQueryObject qo) {
        int total = clientPlanMapper.queryTotal(qo);
        if (total == 0) {
            return new PageResult(total, Collections.emptyList());
        }
        return new PageResult(total, clientPlanMapper.queryRows(qo));
    }

    public void sign(Long id, Integer result_id) {
        clientPlanMapper.sign(id,result_id);
    }
}
